<?php

// 会员充值 提现 消费 表

namespace app\console\model;

use think\Db;
use think\Model;
use app\console\model\Member as MemberModel;
use app\console\model\MemberMessage as MemberMessageModel;
use think\Request;

class MemberWithdraw extends Model
{

    // 会员充值 提现 消费 表 会员表关联
    public function Member()
    {
        return $this->belongsTo('Member', 'member_id', 'id');
    }

    // 姓名
    protected function getMemberNameAttr($value, $data)
    {
        $r = MemberModel::where('id', $data['member_id'])->field('username,name')->find();

        return $r['username'];
    }

    // 模型事件
    protected static function init()
    {

        // 写入前
        self::event('before_write', function ($data) {

            if ($data->status == '1') {

                $model = new MemberMessageModel();
                $model->save(['member_id' => $data->member_id, 'title' => '您的提现已经通过', 'content' => '您的提现已经通过，请查看。', 'create_time' => time(), 'type' => 1]);
            }

        });
    }
}